package com.itr.kbm.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itr.kbm.dao.ListAdminDao;
import com.itr.kbm.model.ListAdmin;

@Repository
public class ListAdminDaoImpl extends AbstractDaoImpl<ListAdmin, Integer> implements ListAdminDao {
	
    protected ListAdminDaoImpl() {
        super(ListAdmin.class);
    }

	public boolean checkInListAdmin (String username, String password) {
		Criteria criteria = getCurrentSession().createCriteria(ListAdmin.class);
    	criteria.add(Restrictions.eq("kodeAdmin", username)); 
    	criteria.add(Restrictions.eq("password", password)); 
    	
    	List<ListAdmin> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public boolean checkInListAdmin (String username) {
		Criteria criteria = getCurrentSession().createCriteria(ListAdmin.class);
    	criteria.add(Restrictions.eq("kodeAdmin", username));
    	
    	List<ListAdmin> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public ListAdmin resetPasswordAdmin (String username) {
		Criteria criteria = getCurrentSession().createCriteria(ListAdmin.class);
    	criteria.add(Restrictions.eq("kodeAdmin", username));
    	
    	List<ListAdmin> list = criteria.list();
        return list.get(0);
	}
	
	public ListAdmin changePasswordAdmin (String username, String password) {
		Criteria criteria = getCurrentSession().createCriteria(ListAdmin.class);
    	criteria.add(Restrictions.eq("kodeAdmin", username));
    	
    	List<ListAdmin> list = criteria.list();
        return list.get(0);
	}
}
